import request from '../utils/request'

// 获取商家列表
export function getMerchants(params) {
  return request({
    url: '/merchants',
    method: 'get',
    params
  })
}

// 获取商家详情
export function getMerchantById(id) {
  return request({
    url: `/merchants/${id}`,
    method: 'get'
  })
}

// 获取营业中的商家
export function getOpenMerchants() {
  return request({
    url: '/merchants/open',
    method: 'get'
  })
}

// 根据状态获取商家
export function getMerchantsByStatus(status, params) {
  return request({
    url: `/merchants/status/${status}`,
    method: 'get',
    params
  })
}

// 获取商家菜单
export function getMenuItemsByMerchant(merchantId, params) {
  return request({
    url: `/menu-items/merchant/${merchantId}`,
    method: 'get',
    params
  })
}

// 获取商家可用菜单
export function getAvailableMenuItemsByMerchant(merchantId) {
  return request({
    url: `/menu-items/merchant/${merchantId}/available`,
    method: 'get'
  })
}

// 获取分类列表
export function getCategories() {
  return request({
    url: '/categories',
    method: 'get'
  })
}

// 根据分类获取菜单项
export function getMenuItemsByCategory(categoryId, params) {
  return request({
    url: `/menu-items/category/${categoryId}`,
    method: 'get',
    params
  })
}

// 搜索菜单项
export function searchMenuItems(params) {
  return request({
    url: '/menu-items/search',
    method: 'get',
    params
  })
}

// 获取菜单项详情
export function getMenuItemById(id) {
  return request({
    url: `/menu-items/${id}`,
    method: 'get'
  })
}

// 获取当前登录商家的信息
export function getMyMerchant() {
  return request({
    url: '/merchants/my',
    method: 'get'
  })
}

// 更新商家营业状态
export function updateMerchantStatus(status) {
  return request({
    url: '/merchants/my/toggle-open',
    method: 'put'
  })
}

// 更新商家信息
export function updateMerchantInfo(data) {
  return request({
    url: '/merchants/my',
    method: 'put',
    data
  })
}
